home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / tests / bstring / RCS / bstring.c,v < prev   
Encoding:
Text File  |  1988-12-15  |  5.7 KB  |  272 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     88.12.15.09.07.52;  author ouster;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     88.04.25.21.41.10;  author ouster;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @Use unsigned chars to make comparisons valid.
  27. @
  28. text
  29. @/* 
  30.  * bstring.c --
  31.  *
  32.  *    This file contains a program that exercises the bstring
  33.  *    library procedures.  Invoke it with no parameters;  it
  34.  *    will print messages on stderr for any problems it detects
  35.  *    with the string procedures.
  36.  *
  37.  * Copyright 1988 Regents of the University of California
  38.  * Permission to use, copy, modify, and distribute this
  39.  * software and its documentation for any purpose and without
  40.  * fee is hereby granted, provided that the above copyright
  41.  * notice appear in all copies.  The University of California
  42.  * makes no representations about the suitability of this
  43.  * software for any purpose.  It is provided "as is" without
  44.  * express or implied warranty.
  45.  */
  46.  
  47. #ifndef lint
  48. static char rcsid[] = "$Header: bstring.c,v 1.1 88/04/25 21:41:10 ouster Exp $ SPRITE (Berkeley)";
  49. #endif not lint
  50.  
  51. #include <stdio.h>
  52. #include <bstring.h>
  53.  
  54. #define error(string) \
  55.     fprintf(stderr, string); \
  56.     exit(1);
  57.  
  58. int
  59. check(srcPtr, numBytes, start)
  60.     unsigned char *srcPtr;    /* First byte to check. */
  61.     int numBytes;        /* How many bytes to check. */
  62.     int start;            /* Bytes should have ascending values starting
  63.                    at start. */
  64. {
  65.     int i;
  66.     for (i = 0; i < numBytes; i++) {
  67.     if (srcPtr[i] != ((start+i)&0377)) {
  68.         return 0;
  69.     }
  70.     }
  71.     return 1;
  72. }
  73.  
  74. int
  75. checkZero(srcPtr, numBytes)
  76.     unsigned char *srcPtr;    /* First byte to check. */
  77.     int numBytes;        /* How many bytes to check. */
  78. {
  79.     int i;
  80.     for (i = 0; i < numBytes; i++) {
  81.     if (srcPtr[i] != 0) {
  82.         return 0;
  83.     }
  84.     }
  85.     if (srcPtr[numBytes] == 0) {
  86.     return 0;
  87.     }
  88.     return 1;
  89. }
  90.  
  91. main()
  92. {
  93.     int result = 0;
  94.     static unsigned char test1[400], test2[400], test3[400];
  95.     int i;
  96.  
  97.     for (i = 0; i < 400; i++) {
  98.     test3[i] = i;
  99.     }
  100.  
  101.     /*
  102.      * bcopy
  103.      */
  104.  
  105.     bcopy(test3, test1, 400);
  106.     if (!check(test1, 400, 0)) {
  107.     error("bcopy error 1\n");
  108.     }
  109.     bcopy(test1+16, test1+32, 127);
  110.     if (!check(test1+32, 127, 16)) {
  111.     error("bcopy error 2\n");
  112.     }
  113.     if ((test1[160] != 160) || (test1[31] != 31)) {
  114.     error("bcopy error 3\n");
  115.     }
  116.     bcopy(test3, test1, 400);
  117.     bcopy(test1+64, test1+16, 127);
  118.     if (!check(test1+16, 127, 64)) {
  119.     error("bcopy error 4\n");
  120.     }
  121.     if ((test1[144] != 144) || (test1[15] != 15)) {
  122.     error("bcopy error 5\n");
  123.     }
  124.     bcopy(test3, test1, 100);
  125.     bcopy(test1+1, test1+16, 32);
  126.     if (!check(test1+16, 32, 1)) {
  127.     error("bcopy error 6\n");
  128.     }
  129.     if ((test1[15] != 15) || (test1[48] != 48)) {
  130.     error("bcopy error 7\n");
  131.     }
  132.     bcopy(test3, test1, 100);
  133.     bcopy(test1+17, test1+8, 32);
  134.     if (!check(test1+8, 32, 17)) {
  135.     error("bcopy error 8\n");
  136.     }
  137.     if ((test1[7] != 7) || (test1[40] != 40)) {
  138.     error("bcopy error 9\n");
  139.     }
  140.     bcopy(test3, test1, 100);
  141.     bcopy(test1+16, test1+3, 32);
  142.     if (!check(test1+3, 32, 16)) {
  143.     error("bcopy error 10\n");
  144.     }
  145.     if ((test1[2] != 2) || (test1[35] != 35)) {
  146.     error("bcopy error 11\n");
  147.     }
  148.     bcopy(test3, test1, 100);
  149.     bcopy(test1+16, test1+33, 32);
  150.     if (!check(test1+33, 32, 16)) {
  151.     error("bcopy error 12\n");
  152.     }
  153.     if ((test1[32] != 32) || (test1[65] != 65)) {
  154.     error("bcopy error 13\n");
  155.     }
  156.     bcopy(test3, test1, 100);
  157.     bcopy(test1+2, test1+6, 64);
  158.     if (!check(test1+6, 64, 2)) {
  159.     error("bcopy error 14\n");
  160.     }
  161.     bcopy(test3, test1, 100);
  162.     bcopy(test1+6, test1+2, 64);
  163.     if (!check(test1+2, 64, 6)) {
  164.     error("bcopy error 15\n");
  165.     }
  166.  
  167.     /*
  168.      * bcmp
  169.      */
  170.  
  171.     bcopy(test3+1, test1, 200);
  172.     bcopy(test3+5, test2, 200);
  173.     test1[135] = 66;
  174.     if (bcmp(test1+8, test2+4, 127) != 0) {
  175.     error("bcmp error 1\n");
  176.     }
  177.     test1[134] = 20;
  178.     if (bcmp(test1+8, test2+4, 127) == 0) {
  179.     error("bcmp error 2\n");
  180.     }
  181.     test1[133] = 19;
  182.     if (bcmp(test1+6, test2+2, 127) != 0) {
  183.     error("bcmp error 3\n");
  184.     }    test1[132] = 18;
  185.     if (bcmp(test1+6, test2+2, 127) == 0) {
  186.     error("bcmp error 4\n");
  187.     }
  188.     if (bcmp(test1+5, test2+1, 127) != 0) {
  189.     error("bcmp error 5\n");
  190.     }
  191.     test1[131] = 17;
  192.     if (bcmp(test1+5, test2+1, 127) == 0) {
  193.     error("bcmp error 6\n");
  194.     }
  195.     test1[72] = 16;
  196.     if (bcmp(test1+8, test2+4, 64) != 0) {
  197.     error("bcmp error 7\n");
  198.     }
  199.     test1[71] = 15;
  200.     if (bcmp(test1+8, test2+4, 64) ==  0) {
  201.     error("bcmp error 8\n");
  202.     }
  203.     bcopy(test3+4, test1, 200);
  204.     if (bcmp(test1+4, test2+3, 64) != 0) {
  205.     error("bcmp error 9\n");
  206.     }
  207.     if (bcmp(test1+5, test2+4, 64) != 0) {
  208.     error("bcmp error 10\n");
  209.     }
  210.  
  211.     /*
  212.      * bzero
  213.      */
  214.  
  215.     bcopy(test3, test1, 200);
  216.     bzero(test1, 1);
  217.     if (!checkZero(test1, 1)) {
  218.     error("bzero error 1\n");
  219.     }
  220.     bcopy(test3, test1, 200);
  221.     bzero(test1, 8);
  222.     if (!checkZero(test1, 8)) {
  223.     error("bzero error 2\n");
  224.     }
  225.     bcopy(test3, test1, 200);
  226.     bzero(test1, 127);
  227.     if (!checkZero(test1, 127)) {
  228.     error("bzero error 3\n");
  229.     }
  230.     bcopy(test3, test1, 200);
  231.     bzero(test1+2, 127);
  232.     if (!checkZero(test1+2, 127)) {
  233.     error("bzero error 4\n");
  234.     }
  235.     bcopy(test3, test1, 200);
  236.     bzero(test1+3, 127);
  237.     if (!checkZero(test1+3, 127)) {
  238.     error("bzero error 5\n");
  239.     }
  240.  
  241.     /*
  242.      * ffs
  243.      */
  244.  
  245.     if (ffs(0) != -1) {
  246.     error("ffs error 1\n");
  247.     }
  248.     if (ffs(1) != 1) {
  249.     error ("ffs error 2\n");
  250.     }
  251.     if (ffs(1<<31) != 32) {
  252.     error ("ffs error 3\n");
  253.     }
  254.  
  255.     return result;
  256. }
  257. @
  258.  
  259.  
  260. 1.1
  261. log
  262. @Initial revision
  263. @
  264. text
  265. @d20 1
  266. a20 1
  267. static char rcsid[] = "$Header: bstring.c,v 1.1 88/04/25 13:09:17 ouster Exp $ SPRITE (Berkeley)";
  268. d66 1
  269. a66 1
  270.     static char test1[400], test2[400], test3[400];
  271. @
  272.